package com.avic.rong.questionOrAnswer;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;

/**
 * 进度对话框
 * created by xtj on 2017/12/7 10:08.
 */

public class RequestProgressDialogWrap {
    public static Context context = null;

    /**
     * createProgressDialog
     *
     * @param cxt
     * @param str
     * @param cancelable
     * @return
     */
    public static ProgressDialog createProgressDialog(Context cxt, String str, boolean cancelable) {
        context = cxt;
        CustomProgressDialog progressDialog = null;
        if (context != null) {
            progressDialog = CustomProgressDialog.createDialog(cxt);
            if (progressDialog == null) {
                return null;
            }
            progressDialog.setMessage(str);
            progressDialog.setCancelable(cancelable);
            progressDialog.setCanceledOnTouchOutside(cancelable);
        }
        return progressDialog;
    }

    /**
     * @param cxt
     * @param stringId
     * @param cancelable
     * @return
     */
    public static ProgressDialog createProgressDialog(Context cxt, int stringId, boolean cancelable) {
        if (cxt != null)
            return createProgressDialog(cxt, cxt.getString(stringId), cancelable);
        return null;
    }


//	}

    public static void dismissProgressDialog(ProgressDialog progressDialog) {
        if (progressDialog != null && progressDialog.isShowing()) {
            if (context != null && !((Activity) context).isFinishing() && progressDialog.getWindow() != null) {
                try {
                    progressDialog.dismiss();
                    progressDialog = null;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
    }

    public static void showProgressDialog(ProgressDialog progressDialog) {
        if (progressDialog != null && !progressDialog.isShowing()) {
            try {
                if (context != null && !((Activity) context).isFinishing() && progressDialog.getWindow() != null) {
                    try {
                        progressDialog.show();
                    } catch (Exception e) {
                    }
                }
            } catch (Exception e) {

                e.printStackTrace();
            }
        }
    }
}
